package com.vfa.test;

import com.vfa.vocaburay.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

public class DynamicQuestionItem extends LinearLayout{

	private ImageView img_Minus;
	private TextView answernum;
	private EditText inputanswer;
	public RadioButton raditem;
	
	private int drawableResource;
	private int position;
	int touch = -1;
	private Context c;
	public DynamicQuestionItem(Context context) {
		super(context);
	    //Sử dụng LayoutInflater để gán giao diện trong list cho class này
        LayoutInflater li = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        li.inflate(R.layout.item_insertedquestion, this, true);
        //Lấy về các View qua Id
        answernum = (TextView) findViewById(R.id.textView_answeritemnum);
        inputanswer = (EditText) findViewById(R.id.editText_answeritemnum);
        raditem = (RadioButton)findViewById(R.id.rad_answeritem);
        img_Minus = (ImageView)findViewById(R.id.img_Minus);
	}
	
	public DynamicQuestionItem(final Context context, int num) {
		super(context);
	    //Sử dụng LayoutInflater để gán giao diện trong list cho class này
        LayoutInflater li = (LayoutInflater) this.getContext()
                                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        li.inflate(R.layout.item_insertedquestion, this, true);
        //Lấy về các View qua Id
        answernum = (TextView) findViewById(R.id.textView_answeritemnum);
        inputanswer = (EditText) findViewById(R.id.editText_answeritemnum);
        raditem = (RadioButton)findViewById(R.id.rad_answeritem);
        img_Minus = (ImageView)findViewById(R.id.img_Minus);
        
       // this.number = num;
        
        //img_Minus.setImageResource(R.drawable.btn_sub);
        img_Minus.setImageResource(drawableResource);
        System.out.println(drawableResource);
        raditem.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				//System.out.println("===================="+number);
				if(InsertQuestion.rightItem != null)
				{
					InsertQuestion.rightItem.raditem.setChecked(false);
				}
				InsertQuestion.rightItem = DynamicQuestionItem.this;
			}
		});
       // answernum.setText(" Answer "+num+":");
        answernum.setText(" Answer :");
        
        
        img_Minus.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(drawableResource == R.drawable.btn_sub)
				{
					System.out.println("onClick img in dynamic = "+position);
					final InsertQuestion insert = (InsertQuestion) context;
					insert.onClick_imgMinus(position);
				}
			}
		});
	}
	
	public void setImageResource(int resource){
		this.drawableResource = resource;
	}
	
	public void setposition(int pos){
		this.position = pos;
	}
	public int getTouch(){
		return 0;
	}
	
	public String getEditText(){
		return inputanswer.getText().toString().trim().replaceAll("[']", "''");
	}
	
	public void setEditText(String str){
		inputanswer.setText(str);
	}
	public void ClearRadCheck() {
		raditem.setChecked(false);
	}
	/*public void setRadioButtonCheck(int index) {
		if(index == number){
		raditem.setChecked(true);}
	}*/
	
	
}
